package com.cykj.pos.controller.api;

import com.cykj.common.core.domain.AjaxResult;
import com.cykj.pos.domain.*;
import com.cykj.pos.domain.dto.IntegralDTO;
import com.cykj.pos.domain.dto.IntegralDetailDTO;
import com.cykj.pos.domain.dto.OrderDTO;
import com.cykj.pos.domain.dto.OrderStatusDTO;
import com.cykj.pos.profit.dto.AddressDTO;
import com.cykj.pos.profit.dto.BizMerchOrderDTO;
import com.cykj.pos.service.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *积分管理Controller
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pos/api/v2/order")
public class PosV2AppOrderController {
    private final IBizMerchOrderService merchOrderService;
    private final IBizMerchantService merchantService;
    private final IBizAllocAdjRecordsService allocAdjRecordsService;
    private final IBizMerchAddressService merchAddressService;

    /**
     * 我的积分首页  获得积分  传递userId  用户id
     * @param orderDTO
     * @return
     */
    @PostMapping("/list")
    public AjaxResult list(@RequestBody OrderDTO orderDTO){
        AjaxResult ajaxResult = AjaxResult.success("我的订单兑换列表获取成功");
        List<BizMerchOrder> merchOrderList = null;
        if(orderDTO.getOrderType()==1){ //查询我的兑换
            merchOrderList = merchOrderService.getOrderListByMerchId(orderDTO);// 根据商户查询订单
        }else if(orderDTO.getOrderType()==2){ // 兑换申请
            merchOrderList = merchOrderService.getOrderListByParentId(orderDTO);// 根据被申请伙伴查询订单
        }
        ajaxResult.put("data",merchOrderList);
        return ajaxResult;
    }


    @PostMapping("/detail")
    public AjaxResult detail(@RequestBody OrderDTO orderDTO){
        AjaxResult ajaxResult = AjaxResult.success("我的订单详情获取成功");
        BizMerchOrder merchOrder = null;
        AddressDTO address = null;
        if(orderDTO.getOrderType()==1){ //查询我的兑换
            merchOrder = merchOrderService.getOrdertById(orderDTO); // 根据商户id查询订单
            address = merchAddressService.getOrderAddress(orderDTO);// 获得订单地址
        }else if(orderDTO.getOrderType()==2){ // 兑换申请
            merchOrder = merchOrderService.getOrdertByParentId(orderDTO);// 根据被申请伙伴id查询订单
            address = merchAddressService.getOrderAddress(orderDTO);// 获得订单地址
        }
        // 通过订单id查询划拨的机器
        List<String> posCodeList = allocAdjRecordsService.getAdjRecordsListByOrderId(orderDTO.getOrderId());
        ajaxResult.put("data",merchOrder);
        ajaxResult.put("posCodeList",posCodeList);
        ajaxResult.put("dataAddress",address);
        return ajaxResult;
    }

    /**
     * 我的积分首页  获得积分  传递userId  用户id
     * @param orderDTO
     * @return
     */
    @PostMapping("/list/type")
    public AjaxResult listType(@RequestBody OrderDTO orderDTO){
        AjaxResult ajaxResult = AjaxResult.success("我的订单兑换列表获取成功");
        List<BizMerchOrderDTO> merchOrderList = null;
        if(orderDTO.getOrderType()==1){ //查询我的兑换
            merchOrderList = merchOrderService.getOrderListByMerchIdAddType(orderDTO);// 根据商户查询订单
        }else if(orderDTO.getOrderType()==2){ // 兑换申请
            merchOrderList = merchOrderService.getOrderListByParentIdAddType(orderDTO);// 根据被申请伙伴查询订单
        }
        ajaxResult.put("data",merchOrderList);
        return ajaxResult;
    }

    @PostMapping("/detail/type")
    public AjaxResult detailType(@RequestBody OrderDTO orderDTO){
        AjaxResult ajaxResult = AjaxResult.success("我的订单详情获取成功");
        BizMerchOrderDTO merchOrder = null;
        AddressDTO address = null;
        if(orderDTO.getOrderType()==1){ //查询我的兑换
            merchOrder = merchOrderService.getOrdertByIdAddType(orderDTO); // 根据商户id查询订单
            address = merchAddressService.getOrderAddress(orderDTO);// 获得订单地址
        }else if(orderDTO.getOrderType()==2){ // 兑换申请
            merchOrder = merchOrderService.getOrdertByParentIdAddType(orderDTO);// 根据被申请伙伴id查询订单
            address = merchAddressService.getOrderAddress(orderDTO);// 获得订单地址
        }
        // 通过订单id查询划拨的机器
        List<String> posCodeList = allocAdjRecordsService.getAdjRecordsListByOrderId(orderDTO.getOrderId());
        ajaxResult.put("data",merchOrder);
        ajaxResult.put("posCodeList",posCodeList);
        ajaxResult.put("dataAddress",address);
        return ajaxResult;
    }

    @PostMapping("/status")
    public AjaxResult getOrderStatus(){
        AjaxResult ajaxResult = AjaxResult.success("获取订单状态列表");
        List<OrderStatusDTO> list = new ArrayList<OrderStatusDTO>();
        OrderStatusDTO orderStatusDTO4 = new OrderStatusDTO(3,"全部");
        OrderStatusDTO orderStatusDTO = new OrderStatusDTO(0,"待发货");
        OrderStatusDTO orderStatusDTO2 = new OrderStatusDTO(1,"已完成");
        OrderStatusDTO orderStatusDTO3 = new OrderStatusDTO(2,"已超时");
        list.add(orderStatusDTO4);
        list.add(orderStatusDTO);
        list.add(orderStatusDTO2);
        list.add(orderStatusDTO3);
        ajaxResult.put("data",list);
        return ajaxResult;
    }
}
